package cn.liuhuan1.blogsModel.controller;

import cn.liuhuan1.entity.ReturnResult;
import cn.liuhuan1.webModelBean.api.AfterUserImp;
import cn.liuhuan1.webModelBean.bo.AfterUserBo;
import cn.liuhuan1.webModelBean.po.WebReturnResultPo;
import cn.liuhuan1.webModelBean.vo.AfterUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author 28067
 * @Auther: liuhuan
 * @Date: 2021/2/19 - 02 - 19 - 12:17
 * @Description:
 * @version: 1.0
 */
@RestController
@RequestMapping("/user/login")
public class LoginController {


    @Autowired
    private AfterUserImp afterUserImp;

    @RequestMapping(value = "/afterLogin",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult afterLogin(@Valid @RequestParam(required = true,value = "username") String username,
                                   @Valid @RequestParam(required = true,value = "password") String password){
        AfterUserVo afterUserVo = afterUserImp.afterLogin(username, password);
        if(afterUserVo == null){
            return ReturnResult.error();
        }
        return ReturnResult.succes(afterUserVo, afterUserVo.getId());
    }

    @RequestMapping(value = "/afterLogOut",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult afterLogOut(@Valid @RequestParam("token") String token){
        return ReturnResult.succes(null,token);
    }

    @RequestMapping(value = "/afterInfo",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult afterInfo(@Valid @RequestParam(value = "token") String token){
        AfterUserVo afterUserVo = afterUserImp.afterInfo(token);
        if(afterUserVo == null){
            return ReturnResult.error();
        }
        return ReturnResult.succes(afterUserVo);
    }

    @RequestMapping(value = "/updateLogin",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult updateLogin(@RequestBody AfterUserBo afterUserBo){
        afterUserImp.updateLogin(afterUserBo);
        return ReturnResult.succes();
    }
}
